﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace OrdonnanceUpdate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnUpDate_Click(object sender, EventArgs e)
        {
            if (txbPath.Text == "")
            {
                MessageBox.Show("Не выбран путь к папке с игрой!");
                return;
            }
      
            String p = txbPath.Text+"\\";

            if (!Directory.Exists(p + "Data\\Sounds"))
            {
                MessageBox.Show("Не найдена папка Data\\Sounds!");
                return;
            }

            if (!Directory.Exists(p + "Data\\Models"))
            {
                MessageBox.Show("Не найдена папка Data\\Models!");
                return;
            }

            String[] sl = File.ReadAllLines("Replace.txt",Encoding.Default);

            for (int i = 0; i < sl.Length-1; i++)
            {
                String[] ssl = sl[i].Split(' ');
                File.Copy("Data\\" + ssl[0], p + ssl[1], true);
            }
               
            // exe
            String[] s = Directory.GetFiles(p, "Ordonnance*.exe");
            for (int i = 0; i < s.Length;i++ )
                File.Delete(s[i]);
            File.Copy("Data\\" + sl[sl.Length - 1], p + sl[sl.Length - 1]);

            MessageBox.Show("Обновление выполнено. Приятной игры.");
            Close();
        }

        /*void AddLog(String s)
        {
            if (txbLog.Text != "") txbLog.Text += "\r\n";
            txbLog.Text += DateTime.Now.ToString("dd.MM.ss H24,mm,ss") + " >> " + s;
            txbLog.Select(txbLog.Text.Length, 0);
            txbLog.ScrollToCaret();
        }*/

        private void btnPath_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txbPath.Text = folderBrowserDialog1.SelectedPath;
            }
        }

    }
}
